<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
<!--      <el-form-item label="项目ID" prop="projectId">-->
<!--        <el-input-->
<!--          v-model="queryParams.projectId"-->
<!--          placeholder="请输入项目ID"-->
<!--          clearable-->
<!--          @keyup.enter="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="订单编号" prop="orderCode">
        <el-input
          v-model="queryParams.orderCode"
          placeholder="请输入订单编号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单日期" prop="orderDate">
        <el-date-picker clearable
          v-model="queryParams.orderDate"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择订单日期">
        </el-date-picker>
      </el-form-item>
<!--      <el-form-item label="订单到货日" prop="requestedDeliveryDate">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.requestedDeliveryDate"-->
<!--          type="date"-->
<!--          value-format="YYYY-MM-DD"-->
<!--          placeholder="请选择订单到货日">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="到货日回复" prop="repliedDeliveryDate">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.repliedDeliveryDate"-->
<!--          type="date"-->
<!--          value-format="YYYY-MM-DD"-->
<!--          placeholder="请选择到货日回复">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="订单总金额" prop="totalAmount">-->
<!--        <el-input-->
<!--          v-model="queryParams.totalAmount"-->
<!--          placeholder="请输入订单总金额"-->
<!--          clearable-->
<!--          @keyup.enter="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="已收款金额" prop="receivedAmount">-->
<!--        <el-input-->
<!--          v-model="queryParams.receivedAmount"-->
<!--          placeholder="请输入已收款金额"-->
<!--          clearable-->
<!--          @keyup.enter="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="支付状态" prop="paymentStatus" style="width: 264.4px">
        <el-select v-model="queryParams.paymentStatus" placeholder="请选择支付状态 " clearable>
          <el-option
            v-for="dict in scm_payment_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>


      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="Plus"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['scm:scmSupplierOrders:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="Edit"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['scm:scmSupplierOrders:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="Delete"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['scm:scmSupplierOrders:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="Download"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['scm:scmSupplierOrders:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="scmSupplierOrdersList" @selection-change="handleSelectionChange">
<!--      <el-table-column type="selection" width="55" align="center" />-->
<!--      <el-table-column label="" align="center" prop="id" />-->
<!--      <el-table-column label="项目ID" align="center" prop="projectId" />-->
      <el-table-column label="订单编号" align="center" prop="orderCode" width="175">
        <template #default="scope">
          <el-button link type="primary" @click="handleOrderCodeClick(scope.row)">
            {{ scope.row.orderCode }}
          </el-button>
        </template>
      </el-table-column>
      <el-table-column label="订单日期" align="center" prop="orderDate" width="100">
        <template #default="scope">
          <span>{{ parseTime(scope.row.orderDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
<!--      <el-table-column label="订单到货日" align="center" prop="requestedDeliveryDate" width="180">-->
<!--        <template #default="scope">-->
<!--          <span>{{ parseTime(scope.row.requestedDeliveryDate, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="到货日回复" align="center" prop="repliedDeliveryDate" width="180">-->
<!--        <template #default="scope">-->
<!--          <span>{{ parseTime(scope.row.repliedDeliveryDate, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="订单总金额" align="center" prop="totalAmount" width="100"/>
      <el-table-column label="已收款金额" align="center" prop="payedAmount" width="100"/>
      <el-table-column label="支付状态" align="center" prop="paymentStatus" width="80">
        <template #default="scope">
          <dict-tag :options="scm_payment_status" :value="scope.row.paymentStatus"/>
        </template>
      </el-table-column>
<!--      <el-table-column label="甲方抬头" align="center" prop="buyerTitle" />-->
<!--      <el-table-column label="甲方地址" align="center" prop="buyerAddress" />-->
<!--      <el-table-column label="甲方联系人" align="center" prop="buyerPerson" />-->
<!--      <el-table-column label="甲方电话" align="center" prop="buyerPhone" />-->
<!--      <el-table-column label="甲方开户银行" align="center" prop="buyerAccountBank" />-->
<!--      <el-table-column label="甲方银行账号" align="center" prop="buyerAccountNumber" />-->
<!--      <el-table-column label="甲方签署日期" align="center" prop="buyerSignDate" width="180">-->
<!--        <template #default="scope">-->
<!--          <span>{{ parseTime(scope.row.buyerSignDate, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="乙方抬头" align="center" prop="sellerTitle" />
<!--      <el-table-column label="乙方地址" align="center" prop="sellerAddress" />-->
<!--      <el-table-column label="乙方联系人" align="center" prop="sellerPerson" />-->
<!--      <el-table-column label="乙方电话" align="center" prop="sellerPhone" />-->
<!--      <el-table-column label="乙方开户银行" align="center" prop="sellerAccountBank" />-->
<!--      <el-table-column label="乙方银行账号" align="center" prop="sellerAccountNumber" />-->
<!--      <el-table-column label="乙方签署日期" align="center" prop="sellerSignDate" width="180">-->
<!--        <template #default="scope">-->
<!--          <span>{{ parseTime(scope.row.sellerSignDate, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="合同文件名字" align="center" prop="contractFileName" />-->
<!--      <el-table-column label="合同文件路径" align="center" prop="contractFile" />-->
      <el-table-column label="备注" align="center" prop="remarks" />
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200">-->
<!--        <template #default="scope">-->
<!--          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['scm:scmSupplierOrders:edit']">修改</el-button>-->
<!--          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['scm:scmSupplierOrders:remove']">删除</el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

    <!--    订单详情-->
    <el-dialog :title="titleOrderDetailsDialog" v-model="openOrderDetailsDialog" width="800px" append-to-body>
      <order-details-dialog :orderId="idForOrderDetailsDialog"  ></order-details-dialog>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="cancelOrderDetailsDialog">取 消</el-button>
        </div>
      </template>
    </el-dialog>
    <!-- 添加或修改供应商订单对话框 -->
    <el-dialog :title="title" v-model="open" width="500px" append-to-body>
      <el-form ref="scmSupplierOrdersRef" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="项目ID" prop="projectId">
          <el-input v-model="form.projectId" placeholder="请输入项目ID" />
        </el-form-item>
        <el-form-item label="订单编号" prop="orderCode">
          <el-input v-model="form.orderCode" placeholder="请输入订单编号" />
        </el-form-item>
        <el-form-item label="订单日期" prop="orderDate">
          <el-date-picker clearable
            v-model="form.orderDate"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择订单日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="订单到货日" prop="requestedDeliveryDate">
          <el-date-picker clearable
            v-model="form.requestedDeliveryDate"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择订单到货日">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="到货日回复" prop="repliedDeliveryDate">
          <el-date-picker clearable
            v-model="form.repliedDeliveryDate"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择到货日回复">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="订单总金额" prop="totalAmount">
          <el-input v-model="form.totalAmount" placeholder="请输入订单总金额" />
        </el-form-item>
        <el-form-item label="已收款金额" prop="receivedAmount">
          <el-input v-model="form.receivedAmount" placeholder="请输入已收款金额" />
        </el-form-item>
        <el-form-item label="支付状态 0:未知 1:未付款, 2:部分付款, 3:已付款, 4:超付款" prop="paymentStatus">
          <el-select v-model="form.paymentStatus" placeholder="请选择支付状态 0:未知 1:未付款, 2:部分付款, 3:已付款, 4:超付款">
            <el-option
              v-for="dict in scm_payment_status"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="甲方抬头" prop="buyerTitle">
          <el-input v-model="form.buyerTitle" placeholder="请输入甲方抬头" />
        </el-form-item>
        <el-form-item label="甲方地址" prop="buyerAddress">
          <el-input v-model="form.buyerAddress" placeholder="请输入甲方地址" />
        </el-form-item>
        <el-form-item label="甲方联系人" prop="buyerPerson">
          <el-input v-model="form.buyerPerson" placeholder="请输入甲方联系人" />
        </el-form-item>
        <el-form-item label="甲方电话" prop="buyerPhone">
          <el-input v-model="form.buyerPhone" placeholder="请输入甲方电话" />
        </el-form-item>
        <el-form-item label="甲方开户银行" prop="buyerAccountBank">
          <el-input v-model="form.buyerAccountBank" placeholder="请输入甲方开户银行" />
        </el-form-item>
        <el-form-item label="甲方银行账号" prop="buyerAccountNumber">
          <el-input v-model="form.buyerAccountNumber" placeholder="请输入甲方银行账号" />
        </el-form-item>
        <el-form-item label="甲方签署日期" prop="buyerSignDate">
          <el-date-picker clearable
            v-model="form.buyerSignDate"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择甲方签署日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="乙方抬头" prop="sellerTitle">
          <el-input v-model="form.sellerTitle" placeholder="请输入乙方抬头" />
        </el-form-item>
        <el-form-item label="乙方地址" prop="sellerAddress">
          <el-input v-model="form.sellerAddress" placeholder="请输入乙方地址" />
        </el-form-item>
        <el-form-item label="乙方联系人" prop="sellerPerson">
          <el-input v-model="form.sellerPerson" placeholder="请输入乙方联系人" />
        </el-form-item>
        <el-form-item label="乙方电话" prop="sellerPhone">
          <el-input v-model="form.sellerPhone" placeholder="请输入乙方电话" />
        </el-form-item>
        <el-form-item label="乙方开户银行" prop="sellerAccountBank">
          <el-input v-model="form.sellerAccountBank" placeholder="请输入乙方开户银行" />
        </el-form-item>
        <el-form-item label="乙方银行账号" prop="sellerAccountNumber">
          <el-input v-model="form.sellerAccountNumber" placeholder="请输入乙方银行账号" />
        </el-form-item>
        <el-form-item label="乙方签署日期" prop="sellerSignDate">
          <el-date-picker clearable
            v-model="form.sellerSignDate"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择乙方签署日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="合同文件名字" prop="contractFileName">
          <el-input v-model="form.contractFileName" placeholder="请输入合同文件名字" />
        </el-form-item>
        <el-form-item label="合同文件路径" prop="contractFile">
          <file-upload v-model="form.contractFile"/>
        </el-form-item>
        <el-form-item label="备注" prop="remarks">
          <el-input v-model="form.remarks" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-divider content-position="center">供应商订单明细信息</el-divider>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" icon="Plus" @click="handleAddScmSupplierOrderItems">添加</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="Delete" @click="handleDeleteScmSupplierOrderItems">删除</el-button>
          </el-col>
        </el-row>
        <el-table :data="scmSupplierOrderItemsList" :row-class-name="rowScmSupplierOrderItemsIndex" @selection-change="handleScmSupplierOrderItemsSelectionChange" ref="scmSupplierOrderItems">
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column label="序号" align="center" prop="index" width="50"/>
          <el-table-column label="产品ID" prop="productId" width="150">
            <template #default="scope">
              <el-input v-model="scope.row.productId" placeholder="请输入产品ID" />
            </template>
          </el-table-column>
          <el-table-column label="采购类型" prop="purchaseCategory" width="150">
            <template #default="scope">
              <el-input v-model="scope.row.purchaseCategory" placeholder="请输入采购类型" />
            </template>
          </el-table-column>
          <el-table-column label="部品类型" prop="demandType" width="150">
            <template #default="scope">
              <el-select v-model="scope.row.demandType" placeholder="请选择部品类型">
                <el-option label="请选择字典生成" value="" />
              </el-select>
            </template>
          </el-table-column>
          <el-table-column label="机种" prop="model" width="150">
            <template #default="scope">
              <el-input v-model="scope.row.model" placeholder="请输入机种" />
            </template>
          </el-table-column>
          <el-table-column label="出厂编号" prop="manufactureNumber" width="150">
            <template #default="scope">
              <el-input v-model="scope.row.manufactureNumber" placeholder="请输入出厂编号" />
            </template>
          </el-table-column>
          <el-table-column label="出厂子编号" prop="manufactureSubNumber" width="150">
            <template #default="scope">
              <el-input v-model="scope.row.manufactureSubNumber" placeholder="请输入出厂子编号" />
            </template>
          </el-table-column>
          <el-table-column label="图号、型号" prop="drawingNumberModel" width="150">
            <template #default="scope">
              <el-input v-model="scope.row.drawingNumberModel" placeholder="请输入图号、型号" />
            </template>
          </el-table-column>
          <el-table-column label="版本" prop="drawingVersion" width="150">
            <template #default="scope">
              <el-input v-model="scope.row.drawingVersion" placeholder="请输入版本" />
            </template>
          </el-table-column>
          <el-table-column label="品名" prop="productName" width="150">
            <template #default="scope">
              <el-input v-model="scope.row.productName" placeholder="请输入品名" />
            </template>
          </el-table-column>
          <el-table-column label="材质" prop="material" width="150">
            <template #default="scope">
              <el-input v-model="scope.row.material" placeholder="请输入材质" />
            </template>
          </el-table-column>
          <el-table-column label="尺寸" prop="size" width="150">
            <template #default="scope">
              <el-input v-model="scope.row.size" placeholder="请输入尺寸" />
            </template>
          </el-table-column>
          <el-table-column label="规格" prop="specification" width="150">
            <template #default="scope">
              <el-input v-model="scope.row.specification" placeholder="请输入规格" />
            </template>
          </el-table-column>
          <el-table-column label="颜色" prop="color" width="150">
            <template #default="scope">
              <el-input v-model="scope.row.color" placeholder="请输入颜色" />
            </template>
          </el-table-column>
          <el-table-column label="单价类型" prop="unitPriceType" width="150">
            <template #default="scope">
              <el-select v-model="scope.row.unitPriceType" placeholder="请选择单价类型">
                <el-option label="请选择字典生成" value="" />
              </el-select>
            </template>
          </el-table-column>
          <el-table-column label="单价" prop="unitPrice" width="150">
            <template #default="scope">
              <el-input v-model="scope.row.unitPrice" placeholder="请输入单价" />
            </template>
          </el-table-column>
          <el-table-column label="数量" prop="quantity" width="150">
            <template #default="scope">
              <el-input v-model="scope.row.quantity" placeholder="请输入数量" />
            </template>
          </el-table-column>
          <el-table-column label="金额" prop="amount" width="150">
            <template #default="scope">
              <el-input v-model="scope.row.amount" placeholder="请输入金额" />
            </template>
          </el-table-column>
          <el-table-column label="模具费" prop="moldCost" width="150">
            <template #default="scope">
              <el-input v-model="scope.row.moldCost" placeholder="请输入模具费" />
            </template>
          </el-table-column>
          <el-table-column label="工装费" prop="jigCost" width="150">
            <template #default="scope">
              <el-input v-model="scope.row.jigCost" placeholder="请输入工装费" />
            </template>
          </el-table-column>
          <el-table-column label="订单到货日" prop="requestedDeliveryDate" width="240">
            <template #default="scope">
              <el-date-picker clearable
                v-model="scope.row.requestedDeliveryDate"
                type="date"
                value-format="YYYY-MM-DD"
                placeholder="请选择订单到货日">
              </el-date-picker>
            </template>
          </el-table-column>
          <el-table-column label="到货日回复" prop="repliedDeliveryDate" width="240">
            <template #default="scope">
              <el-date-picker clearable
                v-model="scope.row.repliedDeliveryDate"
                type="date"
                value-format="YYYY-MM-DD"
                placeholder="请选择到货日回复">
              </el-date-picker>
            </template>
          </el-table-column>
        </el-table>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="ScmSupplierOrders">
import { listScmSupplierOrders, getScmSupplierOrders, delScmSupplierOrders, addScmSupplierOrders, updateScmSupplierOrders } from "@/api/scm/scmSupplierOrders";
import OrderDetailsDialog from "@/views/scm/scmSupplierOrders/orderDetailsDialog.vue";

const { proxy } = getCurrentInstance();
const { scm_payment_status } = proxy.useDict('scm_payment_status');

const scmSupplierOrdersList = ref([]);
const scmSupplierOrderItemsList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const checkedScmSupplierOrderItems = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    projectId: null,
    orderCode: null,
    orderDate: null,
    requestedDeliveryDate: null,
    repliedDeliveryDate: null,
    totalAmount: null,
    receivedAmount: null,
    paymentStatus: null,
    buyerTitle: null,
    buyerAddress: null,
    buyerPerson: null,
    buyerPhone: null,
    buyerAccountBank: null,
    buyerAccountNumber: null,
    buyerSignDate: null,
    sellerTitle: null,
    sellerAddress: null,
    sellerPerson: null,
    sellerPhone: null,
    sellerAccountBank: null,
    sellerAccountNumber: null,
    sellerSignDate: null,
    contractFileName: null,
    contractFile: null,
    remarks: null,
  },
  rules: {
    projectId: [
      { required: true, message: "项目ID不能为空", trigger: "blur" }
    ],
    orderCode: [
      { required: true, message: "订单编号不能为空", trigger: "blur" }
    ],
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询供应商订单列表 */
function getList() {
  loading.value = true;
  listScmSupplierOrders(queryParams.value).then(response => {
    scmSupplierOrdersList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}


// 表单重置
function reset() {
  form.value = {
    id: null,
    projectId: null,
    orderCode: null,
    orderDate: null,
    requestedDeliveryDate: null,
    repliedDeliveryDate: null,
    totalAmount: null,
    receivedAmount: null,
    paymentStatus: null,
    buyerTitle: null,
    buyerAddress: null,
    buyerPerson: null,
    buyerPhone: null,
    buyerAccountBank: null,
    buyerAccountNumber: null,
    buyerSignDate: null,
    sellerTitle: null,
    sellerAddress: null,
    sellerPerson: null,
    sellerPhone: null,
    sellerAccountBank: null,
    sellerAccountNumber: null,
    sellerSignDate: null,
    contractFileName: null,
    contractFile: null,
    remarks: null,
    createBy: null,
    createTime: null,
    updateBy: null,
    updateTime: null
  };
  scmSupplierOrderItemsList.value = [];
  proxy.resetForm("scmSupplierOrdersRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "添加供应商订单";
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  const _id = row.id || ids.value
  getScmSupplierOrders(_id).then(response => {
    form.value = response.data;
    scmSupplierOrderItemsList.value = response.data.scmSupplierOrderItemsList;
    open.value = true;
    title.value = "修改供应商订单";
  });
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["scmSupplierOrdersRef"].validate(valid => {
    if (valid) {
      form.value.scmSupplierOrderItemsList = scmSupplierOrderItemsList.value;
      if (form.value.id != null) {
        updateScmSupplierOrders(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addScmSupplierOrders(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value;
  proxy.$modal.confirm('是否确认删除供应商订单编号为"' + _ids + '"的数据项？').then(function() {
    return delScmSupplierOrders(_ids);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {});
}

/** 供应商订单明细序号 */
function rowScmSupplierOrderItemsIndex({ row, rowIndex }) {
  row.index = rowIndex + 1;
}

/** 供应商订单明细添加按钮操作 */
function handleAddScmSupplierOrderItems() {
  let obj = {};
  obj.productId = "";
  obj.purchaseCategory = "";
  obj.demandType = "";
  obj.model = "";
  obj.manufactureNumber = "";
  obj.manufactureSubNumber = "";
  obj.drawingNumberModel = "";
  obj.drawingVersion = "";
  obj.productName = "";
  obj.material = "";
  obj.size = "";
  obj.specification = "";
  obj.color = "";
  obj.unitPriceType = "";
  obj.unitPrice = "";
  obj.quantity = "";
  obj.amount = "";
  obj.moldCost = "";
  obj.jigCost = "";
  obj.requestedDeliveryDate = "";
  obj.repliedDeliveryDate = "";
  obj.remarks = "";
  scmSupplierOrderItemsList.value.push(obj);
}

/** 供应商订单明细删除按钮操作 */
function handleDeleteScmSupplierOrderItems() {
  if (checkedScmSupplierOrderItems.value.length == 0) {
    proxy.$modal.msgError("请先选择要删除的供应商订单明细数据");
  } else {
    const scmSupplierOrderItemss = scmSupplierOrderItemsList.value;
    const checkedScmSupplierOrderItemss = checkedScmSupplierOrderItems.value;
    scmSupplierOrderItemsList.value = scmSupplierOrderItemss.filter(function(item) {
      return checkedScmSupplierOrderItemss.indexOf(item.index) == -1
    });
  }
}

/** 复选框选中数据 */
function handleScmSupplierOrderItemsSelectionChange(selection) {
  checkedScmSupplierOrderItems.value = selection.map(item => item.index)
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('scm/scmSupplierOrders/export', {
    ...queryParams.value
  }, `scmSupplierOrders_${new Date().getTime()}.xlsx`)
}

// 订单详情
const openOrderDetailsDialog = ref(false);
const titleOrderDetailsDialog = ref("");
const idForOrderDetailsDialog = ref("");
// 在<script setup>中添加
function handleOrderCodeClick(row) {
  // 重置表单
  openOrderDetailsDialog.value = true;
  titleOrderDetailsDialog.value = "查看客户订单详情";
  idForOrderDetailsDialog.value = row.id;
}
function cancelOrderDetailsDialog() {
  openOrderDetailsDialog.value = false;
}

getList();
</script>
